package com.bc.commonentity.log;

import com.dianping.cat.status.StatusExtension;
import com.dianping.cat.status.StatusExtensionRegister;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class HeartbeatExtenstion implements StatusExtension, Initializable {
	private static final Logger logger = LoggerFactory.getLogger(HeartbeatExtenstion.class);
	public HeartbeatExtenstion() throws Exception{
		initialize();
	}
	@Override
	public void initialize() throws InitializationException {
		logger.debug("将cat扩展心跳服务注册到cat");
		StatusExtensionRegister.getInstance().register(this);
	}

	@Override
	public String getDescription() {
		return "掌合天下cat心跳扩展";
	}

	@Override
	public String getId() {
		return "zhtx_cat_heartbeat";
	}

	@Override
	public Map<String, String> getProperties() {
		Map<String, String> maps = new HashMap<String, String>(); 
		maps.put("logQueueSize", String.valueOf(LogMqService.getQueueSize())); 
		maps.put("activeLogThreadCount", String.valueOf(LogMqService.getActiveThreadCount())); 
		maps.put("idleLogThreadCount", String.valueOf(LogMqService.getIdleThreadCount())); 
		return maps;
	}

}
